IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[spPayIns_GetAllPayInsForSchedule]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
	DROP PROCEDURE [dbo].[spPayIns_GetAllPayInsForSchedule]
GO


GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Eric Liew
-- Create date: 6/2/2009
-- Description:	Get all drivers
-- =============================================
CREATE PROCEDURE [dbo].[spPayIns_GetAllPayInsForSchedule]
(
		@ScheduleDate DATETIME,
		@ShiftId	INT
 )
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;


select scheduledrivertaxi.ScheduleDriverTaxiId,
	   scheduledrivertaxi.ScheduleId,
	   scheduledrivertaxi.TaxiId,
	   scheduledrivertaxi.DriverId,
       schedule.ShiftId,
       Schedule.ScheduleDate,
	   driver.firstname,
       driver.LastName,
       Driver.FirstName + ' ' + Driver.LastName AS driverName,
       plate.platenumber,
	   payin.PayInId,
	   payin.PayInDate,
	   payin.cash,
	   payin.m7,
	   payin.eftpos,
	   payin.Expenses,
	   payIn.Comment,
	   PayIn.PayInDue,
	   PayIn.CarriedFwdPayIn,
	   PayIn.Claims,
	   Shift.ShiftDescription,
	   Owner.FirstName AS OwnerFirstName, 
	   Owner.LastName AS OwnerLastName,
	   Owner.FirstName + ' ' + Owner.LastName AS ownerName,
	   Owner.CompanyName AS OwnerCompany
from   payin
right join scheduledrivertaxi
on scheduledrivertaxi.ScheduleDriverTaxiId = payin.scheduledrivertaxiid
left join Driver
on scheduledrivertaxi.driverid = driver.driverid
left join Taxi
on scheduledrivertaxi.taxiid = taxi.taxiid
left join Plate
on taxi.plateid = plate.plateid
inner join Schedule
on Schedule.ScheduleId = ScheduleDriverTaxi.ScheduleId
INNER JOIN Shift
ON Schedule.ShiftId = Shift.ShiftId
left JOIN Owner
ON Owner.OwnerId = Plate.OwnerId
WHERE schedule.ScheduleDate = @ScheduleDate and
schedule.shiftid = @ShiftId
	    

END
GO
